import { degreeInfo, mmInfo, ParameterObjectType } from '@amcax/base';

const _PREFIX = '$__PICK_INPUT_FORMAT#';

export const composeFormat = (formats: string[]) => {
  return `${_PREFIX}${formats.join('|')}`;
};

export const decodeComposedFormat: (encoded: string) => string[] = (
  encoded: string,
) => {
  if (encoded == null) return [];

  if (encoded.startsWith(_PREFIX)) {
    return encoded.replaceAll(_PREFIX, '|').split('|').filter(Boolean);
  }

  return [encoded];
};

// 公式形式的数值输入，一律统一为mm/deg
export const getUnitForExpression = (type: ParameterObjectType) => {
  if (type === ParameterObjectType.Length) {
    return mmInfo;
  }

  if (type === ParameterObjectType.Angle) {
    return degreeInfo;
  }

  return null;
};
